package com.atguigu.gulimall.coupon.service.impl;

import org.springframework.stereotype.Service;
import java.util.Map;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.atguigu.common.utils.PageUtils;
import com.atguigu.common.utils.Query;

import com.atguigu.gulimall.coupon.dao.SeckillSkuRelationDao;
import com.atguigu.gulimall.coupon.entity.SeckillSkuRelationEntity;
import com.atguigu.gulimall.coupon.service.SeckillSkuRelationService;
import org.springframework.util.StringUtils;


@Service("seckillSkuRelationService")
public class SeckillSkuRelationServiceImpl extends ServiceImpl<SeckillSkuRelationDao, SeckillSkuRelationEntity> implements SeckillSkuRelationService {

    @Override
    public PageUtils queryPage(Map<String, Object> params) {

        QueryWrapper<SeckillSkuRelationEntity> wrapper= new QueryWrapper<>();  //  构建wrapper对象

      //  http://localhost:88/api/coupon/seckillskurelation/list?t=1724075463788&page=1&limit=10&key=&promotionSessionId=1

        String  promotionSessionId = (String) params.get("promotionSessionId");  //  从参数中获取场次id

    if(!StringUtils.isEmpty(promotionSessionId)){

        wrapper.eq("promotion_session_id",promotionSessionId);    //  如果参数中有场次id,那么就只查询这个场次关联的sku,
        // 如果参数中没有场次id,那么就查询所有场次关联的所有的sku

    }

        IPage<SeckillSkuRelationEntity> page = this.page(
                new Query<SeckillSkuRelationEntity>().getPage(params),
                wrapper
        );

        return new PageUtils(page);
    }

}